﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using BLL;
using Utils;

namespace UI.ModEmployee
{
    public partial class BankAccountBatch : System.Web.UI.Page
    {
        EmployeeBiz employeeBiz = new EmployeeBiz();
        BankAccountBiz bankAccountBiz = new BankAccountBiz();
        string account = "";
        protected void Page_Init(object sender, EventArgs e)
        {
            if (Session["user"] != null)
            {
                User user = Session["user"] as User;
                account = user.Account;
            }
            else
            {
                JSUtility.Alert(this, "您没有登录!请先登录。");
                return;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataTable dt = employeeBiz.GetNoBankAccountList();
                if (dt.Rows.Count > 0)
                {
                    lbAmount.Text = "共有：" + dt.Rows.Count + " 条记录";
                    gvList.DataSource = dt;
                    gvList.DataBind();
                }
                else
                {
                    lbAmount.Text = "所有最近两个月入职员工都有工资银行账号，不需要设置";
                    btnModi.Visible = false;
                }

            }
        }

        protected void btnModi_Click(object sender, EventArgs e)
        {
            try
            {
                StringBuilder builder = new StringBuilder();
                for (int i = 0; i < gvList.Rows.Count; i++)
                {
                    GridViewRow row = gvList.Rows[i];
                    string empCode = ((Label)row.Cells[0].FindControl("lbEmpCode")).Text;
                    string empName = ((Label)row.Cells[0].FindControl("lbEmpName")).Text;
                    string bankName = ((TextBox)row.Cells[0].FindControl("txtSalaryState")).Text.Trim();
                    string bankAccount = ((TextBox)row.Cells[0].FindControl("txtSalaryAccount")).Text.Trim();
                    if (empCode == "" || bankName == "" || string.IsNullOrWhiteSpace(bankAccount)==true) continue;
                    SortedDictionary<string, string> hList = new SortedDictionary<string, string>();
                    hList.Add("EmpCode", empCode);
                    hList.Add("EmpName", empName);
                    hList.Add("BankName", bankName);
                    hList.Add("BankAccount", bankAccount);
                    bankAccountBiz.Insert(hList);
                }
                JSUtility.Alert(this, "增加成功。");
            }
            catch { JSUtility.Alert(this, "增加失败。"); }
        
          
        }
    }
}